package com.black.utils.file.compress.jar.visitor;


import com.black.utils.file.compress.jar.entity.AnnotationInfo;
import com.black.utils.file.compress.jar.entity.FieldInfo;
import lombok.Getter;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;

/**
 * @author ylx
 */
@Getter
public class JarFieldVisitor extends FieldVisitor implements Opcodes {
    private final FieldInfo fieldInfo;
    public JarFieldVisitor(FieldInfo fieldInfo) {
        super(ASM7);
        this.fieldInfo = fieldInfo;
    }

    /**
     * 访问类中的注解
     *
     * @param desc    注解的描述信息，用于标识注解类型
     * @param visible 注解的可见性，表示注解是否在运行时可见
     * @return 返回一个AnnotationVisitor对象，用于后续访问注解的元素
     */
    @Override
    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
        // 创建一个JarAnnotationVisitor对象，用于处理注解信息
        AnnotationInfo annotationInfo = new AnnotationInfo(desc);
        fieldInfo.addAnnotation(desc, annotationInfo);
        return new JarAnnotationVisitor(annotationInfo);
    }
}
